--- 开封 MB_mag
module(..., package.seeall)
local logtag = "MB_mag"
local dtu, udtu = {}, {}
function setDtu(_dtu, _udtu)
    dtu, udtu = _dtu, _udtu
    if udtu and tonumber(udtu.dtype) == 8 then sys.taskInit(init) end
end
function _pro(d) 
    local _, ins = pack.unpack(d:sub(4, 7), ">f")
    local val = tonumber((d:sub(8, 11)):toHex(), 16)
    lcd.LCD_DATA[3]= "累计流量："..val
    usrdata.update({val,ins})
end
function init()
    sys.wait(200)
    local read_dat ="010310100004410C"
	while true do
        sys.publish("UART_SENT_RDY_3", 3, read_dat:fromHex())
        local res, d = sys.waitUntil("UART_READ_DONE_NEXT_3" , 5000)
        if res then
            if d then
                _pro(d)
            end
            sys.wait(5000)
        else
            lcd.LCD_DATA[3]= "READ TIMEOUT"
        end
	end 
end
